<template>
  <div class="logLogin">
    <pageCard :title-name="'版本管理'" :type="'pageTitle'">
      <div>
        <div class="topText">版本号：</div>
        <el-input
          v-model="search.versionsNumber"
          placeholder="请输入"
          class="searchInput"
          @keyup.enter.native="searchClick"
        />
        <el-button type="primary" class="topBtn" icon="el-icon-search" @click="searchClick">搜索</el-button>
      </div>
      <myTable
        ref="myTable"
        style="height: 100%"
        :row-key="'versionsId'"
        :table-label="tableLabel"
        :table-data="tableData"
        :table-total-size="tableTotalSize"
        :search-data="searchData"
        @getTableData="getTableData"
        @handleSelectionChange="handleSelectionChange"
        @rowClickChange="rowClickChange"
      />
      <pagination
        :table-total-size="tableTotalSize"
        :search-data="searchData"
        @getTableData="$refs.myTable.getTableData()"
      />
    </pageCard>
    <!-- <iframe src="http://localhost:8080/log/logPage" frameborder="0" style="height: 100%;width: 100%;" /> -->
  </div>
</template>

<script>
import { getVersionsRecordData } from '@/api/system-management'
import pageCard from '@/components/page/pageCard'
import myTable from '@/components/Table/index'
import pagination from '@/components/Table/pagination'
import defaultSettings from '@/settings'
import { generateUUID, postMessage, receivedMessage } from '@/utils/index'
export default {
  name: 'SystemLog',
  components: {
    pageCard,
    myTable,
    pagination
  },
  data() {
    return {
      search: {
        versionsNumber: ''
      },
      searchData: {
        pageSize: 15,
        currentPage: 1,
        sort: {},
        params: {}
      },
      // table需要的数据
      tableData: [],
      tableLabel: [
        {
          prop: 'versionsNumber',
          label: '版本号',
          width: 350,
          showOverflowTooltip: true
        },
        {
          prop: 'createTime',
          label: '发布时间',
          width: 350,
          showOverflowTooltip: true
        },
        {
          prop: 'updateContent',
          label: '更新内容',
          showOverflowTooltip: true
        }
      ],
      tableTotalSize: null,
      multipleSelection: [],
      currentRow: {},
      // 日期选择配置
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      callbackFun: null,
      getVersionsRecordDataRequestId: generateUUID()
    }
  },
  mounted() {
    receivedMessage(this.dataHandle)
  },
  methods: {
    dataHandle(result) {
      let self = this
      let e = defaultSettings.isWPF ? result : { data: JSON.parse(result) }
      if (e.data.webInfo.requestId === self.getVersionsRecordDataRequestId) {
        let res = e.data.response
        self.tableData = res.data
        self.tableTotalSize = res.total_count
        self.callbackFun(self.tableData)
      }
    },
    // 获取tableData
    getTableData(cab) {
      if (defaultSettings.isWPF || defaultSettings.isCEF) {
        this.callbackFun = cab
        this.getVersionsRecordDataRequestId = generateUUID()
        let message = {
          RequestUrl: process.env.VUE_APP_URL + '/versionsRecord/getVersionsRecordData',
          RequestMethod: 'POST',
          Headers: {
            contentType: 'application/json'
          },
          QueryParameter: {},
          RequestBody: this.searchData,
          WebInfo: {
            requestId: this.getVersionsRecordDataRequestId
          }
        }
        postMessage(message)
      } else {
        getVersionsRecordData(this.searchData).then((res) => {
          this.tableData = res.data
          this.tableTotalSize = res.total_count
          cab(this.tableData)
        })
      }
    },
    // 搜索
    searchClick() {
      this.searchData.currentPage = 1
      this.searchData.params['versionsNumber'] = this.search.versionsNumber
      this.$refs.myTable.getTableData()
    },
    // 复选框回调函数
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 点击行回调函数
    rowClickChange(val) {
      this.currentRow = val
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../styles/pageTableTop.scss';
.logLogin {
  height: 99%;
}
</style>
